package ds_recommended.self_chuli

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions.col

import java.util.Properties

object image_url_alter {
  def main(args: Array[String]): Unit = {
    val spark=SparkSession.builder()
      .master("local[*]")
      .appName("修改图片连接的路径")
      .getOrCreate()

    val connect=new Properties()
    connect.setProperty("user","root")
    connect.setProperty("password","123456")
    connect.setProperty("driver","com.mysql.jdbc.Driver")


    spark.read
      .jdbc("jdbc:mysql://192.168.67.193:3307/source?useSSL=false","shop_info",connect)
      .createOrReplaceTempView("data")


   val result= spark.sql(
      """
        |select
        |class_id,class_name,product_id,title,price,address,buy_number,
        |concat("images/",split(image_url,".com/")[1]) as image_url,
        |info_url,rating
        |from data
        |""".stripMargin)


    result.write.mode("overwrite")
      .option("batchsize", "100000") // 每次插入 1000 条记录
      .option("isolationLevel", "NONE")
      .option("autocommit", "false")
      .jdbc("jdbc:mysql://192.168.67.193:3307/ods?useSSL=false","shop_info",connect)








    spark.close()
  }

}
